********************************************************************************
***************** Table A: Sectoral FDI and Conflict ***************************
********************************************************************************
use FDI&Conflict.dta, clear
gen s = incidencev414==1&onset2v414==0

#delimit ;
global xmat1="lmrpe llrgdpcap llpop llgrowthrate lpolity2 lloil_gas_cap elf85 
relfrac lmtnest ncontig coldwar t1_onset2 t2_onset2 t3_onset2"; 
#delimit cr

* Model 1
probit onset2v414 cr_ISICPrimary_cap $xmat1 if s==0, vce(r)

* Model 2
probit onset2v414 cr_ISICSecondary_cap $xmat1 if s==0, vce(r)

* Model 3
probit onset2v414 cr_ISICTertiary_cap $xmat1 if s==0, vce(r)

* Model 4
ivprobit onset2v414 (cr_ISICPrimary_cap=lwdist) $xmat1 if s==0, vce(r)
test lwdist

* Model 5
eststo secIV: ivprobit onset2v414 (cr_ISICSecondary_cap=lwdist) $xmat1 if s==0, vce(r)
test lwdist

* Model 6
ivprobit onset2v414 (cr_ISICTertiary_cap=lwdist) $xmat1 if s==0, vce(r)
test lwdist

********************************************************************************
*************************** Table B: FDI and Conflict Type *********************
********************************************************************************
#delimit ;
global xmat1="lmrpe llrgdpcap llpop llgrowthrate lpolity2 lloil_gas_cap elf85 
relfrac lmtnest ncontig coldwar"; 
#delimit cr

* Model 1
ivprobit onset2gov (cr_rfdicap=lwdist) $xmat1 /// 
t1_govconf t2_govconf t3_govconf if onset2gov!=0|incidencev414==0, vce(r) 
test lwdist

* Model 2
ivprobit onset2ter (cr_rfdicap=lwdist) $xmat1 ///
t1_terrconf t2_terrconf t3_terrconf if onset2ter!=0|incidencev414==0, vce(r)
test lwdist

********************************************************************************
********** Table C: Conflict Presence/Duration and Number of Conflicts *********
********************************************************************************
#delimit ;
global xmat1="lmrpe llrgdpcap llpop llgrowthrate lpolity2 lloil_gas_cap elf85 
relfrac lmtnest ncontig coldwar t1_incidence t2_incidence t3_incidence"; 
#delimit cr

**Model 1: IV probit
ivprobit incidencev414 (cr_rfdicap=lwdist) $xmat1, vce(r) 
test lwdist

**Model 2: IV logit
reg cr_rfdicap lwdist $xmat1, vce(r)
test lwdist
estadd scalar fstat = r(F)
estadd scalar pval = r(p) 
predict resids_inci2, resid

bootstrap, rep(1000) seed(11011) strata(ccode): ///
logit incidencev414 cr_rfdicap $xmat1 resids_inci2, vce(r)

* Model 3
ivreg2 nototconfv414 (cr_rfdicap=lwdist) $xmat1, gmm robust first

********************************************************************************
****** Table D: FDI and Civil Conflict Onset: Different Intermittent Years *****
********************************************************************************
foreach x in 1 2 5 8 20 {
	gen subyears`x'=(incidencev414==1)
	replace subyears`x'=0 if onset`x'v414==1
}

gen subyearsnew=(incidencev414==1)
replace subyearsnew=0 if newconflictinyearv414==1

#delimit ;
global xmat1="lmrpe llrgdpcap llpop llgrowthrate lpolity2 lloil_gas_cap elf85 
relfrac lmtnest ncontig coldwar"; 
#delimit cr

*Model 1
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 t1_onset2 t2_onset2 t3_onset2, vce(r)
test lwdist

*Model 2
ivprobit onset1v414 (cr_rfdicap=lwdist) $xmat1 t1_onset1 t2_onset1 t3_onset1 if subyears1==0, vce(r)
test lwdist

*Model 3
ivprobit onset5v414 (cr_rfdicap=lwdist) $xmat1 t1_onset5 t2_onset5 t3_onset5 if subyears5==0, vce(r)
test lwdist

*Model 4
ivprobit onset8v414 (cr_rfdicap=lwdist) $xmat1 t1_onset8 t2_onset8 t3_onset8 if subyears8==0, vce(r)
test lwdist

*Model 5
ivprobit onset20v414 (cr_rfdicap=lwdist) $xmat1 t1_onset20 t2_onset20 t3_onset20 if subyears20==0, vce(r)
test lwdist

*Model 6
ivprobit newconflictinyearv414 (cr_rfdicap=lwdist) $xmat1 ///
t1_new t2_new t3_new if subyearsnew==0,  vce(r)
test lwdist

********************************************************************************
********** Table E: Different Transformations and Measures of FDI **************
********************************************************************************
#delimit ;
global xmat1="lmrpe llrgdpcap llpop llgrowthrate lpolity2 lloil_gas_cap elf85 
relfrac lmtnest ncontig coldwar t1_onset2 t2_onset2 t3_onset2"; 
#delimit cr

*Model 1
ivprobit onset2v414 (rfdicap=lwdist) $xmat1 if s==0,vce(r)
test lwdist

*Model 2
ivprobit onset2v414 (fdigdp_unctad=lwdist) $xmat1 if s==0, vce(r)
test lwdist

*Model 3
ivprobit onset2v414 (cr_fdigdp=lwdist) $xmat1 if s==0, vce(r)
test lwdist

* Model 4
ivprobit onset2v414 (cr_rfdistockcap=lwdist) $xmat1 if s==0, vce(r)
test lwdist

********************************************************************************
********** Table G: Military Interventions & U.S. Covert Operations ************
********************************************************************************
* Model 1
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 lwt_nonneu_int if s==0, vce(r)
test lwdist

* Model 2
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 lwt_favgov_int if s==0, vce(r)
test lwdist

* Model 3
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 lwt_favreb_int if s==0, vce(r)
test lwdist

* Model 4
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 lcovertop_us if s==0, vce(r)
test lwdist

********************************************************************************
*********************** Table G: First-Stage Results *************************** 
********************************************************************************
* Model 1
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 if s==0, vce(r) first
test lwdist

* Model 2
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 llopen if s==0, vce(r) first
test lwdist

* Model 3
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 weightedvote logaidgdp /// 
weightedalliance weightedcolony  if s==0, vce(r) first
test lwdist

* Model 4
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 lwt_all_int  if s==0, vce(r) first
test lwdist

* Model 5
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 if Oil==0&s==0, vce(r) first
test lwdist

* Model 6
ivprobit onset2v414 (cr_nonprimary=lwdist) $xmat1 if s==0, vce(r) first
test lwdist

********************************************************************************
******* Table H: FDI and Civil Conflict Onset (Linear Probability Model) *******
********************************************************************************
* Model 1
reg onset2v414 cr_rfdicap $xmat1 if s==0, robust

* Model 2
ivreg2 onset2v414 (cr_rfdicap=lwdist) $xmat1 if s==0, robust gmm first

* Model 3
ivreg2 onset2v414 (cr_rfdicap=lwdist) $xmat1 llopen if s==0, robust gmm first

* Model 4
ivreg2 onset2v414 (cr_rfdicap=lwdist) $xmat1 ///
weightedvote logaidgdp weightedalliance weightedcolony if s==0, robust gmm first

* Model 5
ivreg2 onset2v414 (cr_rfdicap=lwdist) $xmat1 lwt_all_int if s==0, robust gmm first

* Model 6
ivreg2 onset2v414 (cr_rfdicap=lwdist) $xmat1 if Oil==0&s==0, robust gmm first

* Model 7
ivreg2 onset2v414 (cr_nonprimary=lwdist) $xmat1 if s==0, robust gmm first

********************************************************************************
********** Table I: Reduced Form (Most Exogenous Covariates Only) **************
********************************************************************************
#delimit ;
global xmat1="llpop elf85 relfrac lmtnest ncontig coldwar 
t1_onset2 t2_onset2 t3_onset2"; 
#delimit cr

* Model 1
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 if s==0, vce(r) first
test lwdist

* Model 2
ivprobit onset2v414 (cr_rfdicap=lwdist) $xmat1 if Oil==0&s==0, vce(r) first
test lwdist

* Model 3
ivprobit onset2v414 (cr_nonprimary=lwdist) $xmat1 if s==0, vce(r) first
test lwdist


********************************************************************************
************************ Table J: Discriptive Stats ****************************
********************************************************************************
egen nomiss = rowmiss(incidencev414 cr_rfdicap lwdist lmrpe  llrgdpcap llpop ///
llgrowthrate lpolity2 lloil_gas_cap elf85 relfrac lmtnest ncontig coldwar ) 

sum cr_rfdicap cr_rfdistockcap lwdist lmrpe lltax_m lenrollpri_m llrgdpcap llpop ///
llgrowthrate lpolity2 lloil_gas_cap elf85 relfrac lmtnest ncontig coldwar ///
weightedvote logaidgdp weightedalliance weightedcolony lwt_all_int if nomiss==0

********************************************************************************
********************* Table K: Correlation Matrix ******************************
********************************************************************************
pwcorr cr_rfdicap cr_rfdistockcap lwdist lmrpe lltax_m lenrollpri_m llrgdpcap llpop ///
llgrowthrate lpolity2 lloil_gas_cap elf85 relfrac lmtnest ncontig coldwar ///
weightedvote logaidgdp weightedalliance weightedcolony lwt_all_int if nomiss==0
